package com.ftg.elvis.mapper;

import com.ftg.elvis.pojo.Product;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AdminProductMapper {


	@Select("select count(*) from product p where p.bid in (select u.bid from user_brand u where u.username = #{arg0}) and p.pname like concat('%',#{arg1},'%')")
	int getCount(String username, String pname);

	@Select("select p.* from product p where p.bid in (select u.bid from user_brand u where u.username = #{arg0}) and p.pname like concat('%',#{arg1},'%') order by ptime desc limit #{arg2}, #{arg3}")
	List<Product> showAll(String username, String pname, int page, int limit);

	@Insert("insert into product(pid,bid,pname,pintroduce,plogo) values(#{pid}, #{bid}, #{pname}, #{pintroduce}, #{plogo})")
	int add(Product product);

	@Update("update product set pname = #{pname}, pintroduce = #{pintroduce}, plogo = #{plogo} where pid = #{pid}")
	int update(Product product);

	@Delete("delete from product where pid = #{pid}")
	int delete(String pid);

	@Select("select bid from user_brand where username = #{username} limit 1")
	String getBid(String username);
}
